package com.xh.audit.controller.project;

import com.mybatisflex.core.paginate.Page;
import com.xh.audit.entity.project.AuditEvidence;
import com.xh.audit.service.AuditEvidenceService;
import com.xh.audit.vo.webform.AuditEvidenceQuery;
import com.xh.common.R;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * <p>
 * 审计取证证据 前端控制器
 * </p>
 *
 * @author lhl
 * @since 2023-10-19
 */
@RestController
@RequestMapping("/audit-evidence")
@RequiredArgsConstructor
@Validated
public class AuditEvidenceController {
    private final AuditEvidenceService auditEvidenceService;

    @PostMapping("/save")
    public R<AuditEvidence> save(@RequestBody
                                 @Validated
                                         AuditEvidence tosave) {
        boolean saveFlag = auditEvidenceService.saveOrUpdate(tosave);

        if (saveFlag) {
            return R.success(auditEvidenceService.getById(tosave.getId()));
        }
        return R.failed("保存失败");
    }

    @PostMapping("/queryByPage")
    public R<Page<AuditEvidence>> query(@RequestBody
                                        @Validated
                                                AuditEvidenceQuery queryPage) {

        Page<AuditEvidence> page1 = auditEvidenceService.page(queryPage.getPageInfo(), queryPage.queryWrapperBuild());
        return R.success(page1);
    }

   /* @PostMapping("/info/{id}")
    public R<AuditEvidence> info(@PathVariable
                                 @Validated
                                 @NotNull(message = "id不能空")
                                         Integer id) {

        AuditEvidence byId = auditEvidenceService.getById(id);
        return R.success(byId);
    }*/

    @PostMapping("/del")
    public R<AuditEvidence> del(@RequestBody
                                @Validated
                                @NotEmpty(message = "ids 集合不能空")
                                        List<Integer> ids) {
        auditEvidenceService.removeByIds(ids);
        return R.success("删除成功");
    }

}
